package com.tzz.service.impl;

import com.tzz.dao.ProductDao;
import com.tzz.entity.Product;
import com.tzz.exception.AddExistException;
import com.tzz.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
@Transactional(rollbackFor = Exception.class)
public class ProductServiceImpl implements ProductService {

    @Autowired
    ProductDao productDao;

    @Override
    public List<Product> findProductsByIdName(Product product) {
        return productDao.getProducts(product);
    }

    @Override
    public void addProduct(Product product) throws AddExistException {
        if(productDao.getProducts(product).size() > 0){
            throw new AddExistException("产品信息已存在");
        }else {
            productDao.insertProduct(product);
        }
    }

    @Override
    public void deleteProductById(Integer id) {
        productDao.deleteProductById(id);
    }

}
